SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for luck_draw
-- ----------------------------
DROP TABLE IF EXISTS `luck_draw`;
CREATE TABLE `luck_draw`  (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`balance` decimal(10, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '金币',
`point` decimal(10, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '银币',
`day_turnplate_num` int(11) UNSIGNED NULL DEFAULT 0 COMMENT '日转盘',
`week_turnplate_num` int(11) UNSIGNED NULL DEFAULT 0 COMMENT '周转盘',
`total_commission` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '累计佣金',
`commission` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '当前佣金',
`used_commission` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '已提现佣金',
`total_pay` bigint(11) NOT NULL DEFAULT 0 COMMENT '累计流水',
`total_recharge` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '累计充值',
`grow_value` int(11) NOT NULL DEFAULT 0 COMMENT '成长值',
`is_reach` tinyint(1) NOT NULL DEFAULT 0 COMMENT '五日流水 0达标 1不达标',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`cashed_commission` decimal(10, 2) NOT NULL DEFAULT 0.00,
`total_income` bigint(20) NOT NULL DEFAULT 0 COMMENT '总兑换价',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `user_id`(`user_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 200 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC;





<template>
  <div class="contentCate">
    <el-card class="box-card" v-if="status === 'index'">
      <el-row>
        <el-input
          v-model="searchParams.user_id"
          placeholder="请输入用户ID"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-input
          v-model="searchParams.boxs"
          placeholder="请输入箱数"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getData"
          v-if="has('challengeBoxPrizesEmptys/index')"
        >搜索</el-button
        >
        <el-button
          type="info"
          icon="el-icon-refresh"
          size="mini"
          @click="reset"
          v-if="has('challengeBoxPrizesEmptys/index')"
        >重置</el-button
        >
      </el-row>
      <el-table
        :data="data.data"
        v-loading="table_loading"
        row-key="id"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column
          fixed
          prop="id"
          label="ID"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="user_id"
          label="用户ID"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="challenge_box_id"
          label="擂台ID"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="boxs"
          label="箱数"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="num"
          label="空数"
          align="center"
          v-slot:default="{ row }"
        >
          <el-input
            @blur="updateEmpty(row)"
            @click.native="row.focus = true"
            v-model="row.num"
          ></el-input>
        </el-table-column>
        <el-table-column
          prop="empty_num"
          label="原始空数"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="created_at"
          label="操作时间"
          align="center"
        ></el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="200" :key="Math.random()">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="mini"
              @click="delPrize(scope.row.id, scope.$index)"
              v-if="has('challengeBoxPrizesEmptys/destroy')"
            >删除
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="searchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="data.total"
        @size-change="changeSize"
        @current-change="changePage"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
import api from "../../api/api.js";
export default {
  name: "contentCate",
  data() {
    return {
      status: "index", // 页面控制
      data: [], // 表格诗句
      table_loading: true, // 表格加载中
      loading: false, //全局加载中
      pageSizes: [10, 20, 50, 100, 200, 500, 800, 1000, 2000], // 每页条数默认10
      searchParams: {
        // 搜索参数
        user_id :'',
        boxs :'',
        page: 1,
        limit: 10
      }
    };
  },
  created() {
    this.getData();
  },

  methods: {
    // 加载中
    load() {
      this.loading = this.$loading({
        lock: true,
        text: "数据加载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },
    // 取消加载
    unload() {
      this.loading.close();
    },
    // 获取所有数据
    getData() {
      this.table_loading = true;
      api.challengeBoxPrizesEmptys
        .index({ params: this.searchParams })
        .then(res => {
          if (res.data.code == 200) {
            this.table_loading = false;
            this.data = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    //改变兑换价格
    updateEmpty(row) {
      this.$nextTick(() => {
        this.load();
        api.challengeBoxPrizesEmptys
          .updateEmpty(row)
          .then(res => {
            if (res.data.code === 200) {
              this.unload();
              this.$message({
                type: "success",
                message: "修改成功!"
              });
              // this.status = "edit";
              this.editParams = res.data.data;
            }
          })
          .catch(error => {
            console.log(error);
          });
      });
    },
    delPrize(id, index) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      })
        .then(() => {
          this.load();
          api.challengeBoxPrizesEmptys
            .del(id)
            .then(res => {
              this.unload();
              if (res.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
                this.data.data.splice(index, 1);
                this.data.total--;
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },

    // 重置搜索参数重新搜索
    reset() {
      this.init();
      this.getData();
    },
    // 初始化
    init() {
      this.searchParams.user_id = "";
      this.searchParams.boxs = "";
    },
    // 改变每页条数时
    changeSize(limit) {
      this.searchParams.limit = limit;
      this.getData();
    },
    // 改变当前页码时
    changePage(page) {
      this.searchParams.page = page;
      this.getData();
    }
  }
};
</script>

<style scoped lang="less">
.contentCate {
  margin: 0 auto;
  .search {
    margin: 0 auto 10px auto;
  }
}
</style>
